﻿//EmulationDebugPanel.xaml.cs
//Copyright (c) 2013 StockSharp LLC, all rights reserved.
//This code module is part of StockSharp library.
//This code is licensed under the GNU GENERAL PUBLIC LICENSE Version 3.
//See the file License.txt for the license details.
//More info on: http://stocksharp.com

namespace StockSharp.Xaml
{
	using System.Windows;

	using StockSharp.Algo.Storages;
	using StockSharp.Algo.Testing;

	/// <summary>
	/// Графическая панель для работы с <see cref="EmulationDebug"/>.
	/// </summary>
	public partial class EmulationDebugPanel
	{
		/// <summary>
		/// Создать <see cref="EmulationDebugPanel"/>.
		/// </summary>
		public EmulationDebugPanel()
		{
			InitializeComponent();
		}

		private EmulationDebug _debug;
		private RealTimeEmulationTrader<DataFeedTrader> _trader;

		/// <summary>
		/// Эмуляционный шлюз.
		/// </summary>
		public RealTimeEmulationTrader<DataFeedTrader> Trader
		{
			get { return _trader; }
			set
			{
				if (_trader == value)
					return;

				_trader = value;

				if (value != null)
				{
					_debug = EmulationDebug.Get(value);
					FillDebug();
				}
				else
					_debug = null;
			}
		}

		private void FillDebug()
		{
			_debug.BreakOnNewDepth = ByDepth.IsChecked == true;
			_debug.BreakOnNewMyTrade = ByMyTrade.IsChecked == true;
			_debug.BreakOnNewOrder = ByOrder.IsChecked == true;
			_debug.BreakOnNewTrade = ByTrade.IsChecked == true;
		}

		private void OnClick(object sender, RoutedEventArgs e)
		{
			if (_debug == null)
				return;

			FillDebug();
		}
	}
}